﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace JXT.PrimaryKey.Batman.Domain.Repositories
{
    /// <summary>
    /// 存储上下文对象
    /// </summary>
    public abstract class RepositoryContext : IDisposable
    {
        /// <summary>
        /// 配置名称
        /// </summary>
        public string ConfigurationName { get; protected set; }

        /// <summary>
        /// 内置存储对象实例
        /// </summary>
        public object ObjectContext { get; protected set; }

        /// <summary>
        /// 开启事务
        /// </summary>
        public abstract void BeginTransaction();

        /// <summary>
        /// 提交事务
        /// </summary>
        public abstract void CommitTransaction();

        /// <summary>
        /// 事务回滚
        /// </summary>
        public abstract void RollbackTransaction();

        /// <summary>
        /// 结束事务
        /// </summary>
        public abstract void DisposeTransaction();

        public virtual void Dispose()
        {
            if (ObjectContext is IDisposable)
            {
                (ObjectContext as IDisposable).Dispose();
            }
        }
    }
}
